﻿using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Demos.util;
using DXApplicationTangche.service;
using DXApplicationTangche.UC.圣同润.merchant;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 广州爱特安为科技.UC.圣同润.客服.售后
{
    public partial class Form售后订单详情 : DevExpress.XtraEditors.XtraForm
    {
        private ViewRefundOrderDTO viewRefundOrderDTO;
        public Form售后订单详情(ViewRefundOrderDTO viewRefundOrderDTO)
        {
            InitializeComponent();
            this.viewRefundOrderDTO = viewRefundOrderDTO;
            this.refresh();
        }

        private void refresh()
        {
            //  商品详情
            ProductDao productDao = MerchantService.getProductById(long.Parse(this.viewRefundOrderDTO.product_id));
            try { this.pictureBox商品图片.Image = FileService.GetImageByUrl(productDao.image); } catch { }
            this.textBox商品价格.Text = productDao.price;
            this.textBox商品库存.Text = productDao.stock.ToString();
            //  订单详情
            this.textBox退回单号.Text = this.viewRefundOrderDTO.order_sn;
            this.textBox收件人.Text = this.viewRefundOrderDTO.real_name;
            this.textBox电话.Text = this.viewRefundOrderDTO.user_phone;
            this.textBox地址.Text = this.viewRefundOrderDTO.user_address;
            this.textBox下单时间.Text = this.viewRefundOrderDTO.addTime.ToString("yyyy-MM-dd");
            this.textBox售后申请时间.Text = this.viewRefundOrderDTO.apply_time.ToString("yyyy-MM-dd");
            this.textBox商品信息.Text = this.viewRefundOrderDTO.product_name;
            this.textBox数量.Text = this.viewRefundOrderDTO.total_num.ToString();
            this.textBox退款金额.Text = this.viewRefundOrderDTO.refund_amount_requested.ToString();
            this.textBox品牌商.Text = this.viewRefundOrderDTO.name;
            this.textBox售后类型.Text = this.viewRefundOrderDTO.type;
            this.textBox揽收状态.Text = this.viewRefundOrderDTO.is_collect;
            this.textBox订单状态.Text = this.viewRefundOrderDTO.status;
            this.textBox退款状态.Text = this.viewRefundOrderDTO.order_after_status_desc;
            this.memoEdit售后状态.Text = this.viewRefundOrderDTO.aftersale_status_desc;
            //  订单记录
            this.gridControl订单记录.DataSource = this.viewRefundOrderDTO.refundOrderRecordData.order_data;
            this.gridView订单记录.RefreshData();
            //  售后记录
            this.gridControl售后记录.DataSource = this.viewRefundOrderDTO.refundOrderRecordData.second_order_data;
            this.gridView售后记录.RefreshData();
            //  售后编辑
            this.textBox退回物流公司.Text = this.viewRefundOrderDTO.refundOrderEditDTO.return_express_company;
            this.textBox退回物流单号.Text = this.viewRefundOrderDTO.refundOrderEditDTO.return_express_order_no;
            List<EditVO> editVOs = new List<EditVO>();
            foreach (String item in this.viewRefundOrderDTO.refundOrderEditDTO.product_pic)
            {
                editVOs.Add(new EditVO("商品截图", item));
            }
            foreach (String item in this.viewRefundOrderDTO.refundOrderEditDTO.tracking_number)
            {
                editVOs.Add(new EditVO("快递面单照片", item));
            }
            foreach (String item in this.viewRefundOrderDTO.refundOrderEditDTO.pack_pic)
            {
                editVOs.Add(new EditVO("快递箱本体照片", item));
            }
            foreach (String item in this.viewRefundOrderDTO.refundOrderEditDTO.express_freight_photo)
            {
                editVOs.Add(new EditVO("快递面单", item));
            }
            this.gridControl编辑售后.DataSource = editVOs;
            this.tileView编辑售后.RefreshData();
        }
    }

    public class EditVO
    {
        public String type { get; set; }
        public String picUrl { get; set; }
        public Image pic { get; set; }
        public EditVO(String type, String picUrl)
        {
            this.type = type;
            this.picUrl = picUrl;
            try
            {
                this.pic = FileService.GetImageByUrl(picUrl);
            }
            catch { }
        }
    }
}